package com.demo.studentmanager;

import android.os.Bundle;
import android.view.MenuItem;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import com.demo.studentmanager.databinding.ActivityHomeBinding;
import com.example.applicationdemo.R;
import com.google.android.material.navigation.NavigationBarView;

public class HomeActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityHomeBinding binding = ActivityHomeBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        showFragment(new StudentManagerFragment());
        binding.bottomView.setOnItemSelectedListener(new NavigationBarView.OnItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                if (item.getItemId() == R.id.classmate) {
                    showFragment(new StudentManagerFragment());
                }
                if (item.getItemId() == R.id.mine) {
                    showFragment(new MineFragment());
                }
                if (item.getItemId() == R.id.lesson) {
                    showFragment(new CourseFragment());
                }
                return true;
            }
        });
    }

    private void showFragment(Fragment fragment) {
        getSupportFragmentManager().beginTransaction().replace(R.id.root, fragment).commit();
    }
}